package com.chen.service.Impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.db.DaoTemplate;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chen.common.Result;
import com.chen.mapper.InfoMapper;
import com.chen.mapper.UserMapper;
import com.chen.pojo.User;
import com.chen.service.UserService;
import com.chen.utils.TokenUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.Date;

/**
 * @author chenchao
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;



    //更新
    public Result<?> updateUser(User user){

        return Result.success(userMapper.updateById(user));
    }


    @Override
    public Boolean saveUser(User users) {
        if (users.getId() == null){
            users.setPassword("123456");
            String date = DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss");
            users.setRegtime(date);
            users.setAddress("地球");
            users.setIntroduce("介绍一下自己吧");
            users.setAvatar("https://img2.baidu.com/it/u=2755068677,1416942527&fm=253&fmt=auto&app=120&f=JPEG?w=200&h=200");
            return save(users);
        }else {
            return updateById(users);
        }

    }



}
